import React, { useEffect, useRef, useState } from "react";
import {Form,Input,Button,Upload} from 'antd';
import {InboxOutlined } from '@ant-design/icons';
import request from '../../../../static/requests'
import { useHistory } from "react-router-dom";
const formItemLayout = {
    labelCol: {
        span: 6,
    },
    wrapperCol: {
        span: 14,
    },
};
const normFile = (e) => {
    if (Array.isArray(e)) {
        return e;
    }
    return e && e.fileList;
};
export default () => {
    let history = useHistory();
        const onFinish =async (values) => {
            console.log(values);
            let data = await request("https://budbud.top/background/subject/detail/post", {
                method: "POST",
                data: values
            })
            if(data.data.code==0){
                history.push("/")
                }
        };
    return (
        <Form
            name="validate_other"
            {...formItemLayout}
            onFinish={onFinish}
        >
            <Form.Item label="添加">
                <span className="ant-form-text">轮播图片</span>
            </Form.Item>
            <Form.Item
                name="name"
                label="标题"
            >
                <Input />
            </Form.Item>
            <Form.Item
                name="summary"
                label="summary"
            >
                <Input />
            </Form.Item>
            <Form.Item label="图片">
                <Form.Item name="dragger" valuePropName="fileList" getValueFromEvent={normFile} noStyle>
                    <Upload.Dragger name="files" action="https://budbud.top/background/upload/image">
                        <p className="ant-upload-drag-icon">
                            <InboxOutlined />
                        </p>
                        <p className="ant-upload-text">请选择你的图片</p>
                    </Upload.Dragger>
                </Form.Item>
            </Form.Item>
            <Form.Item
                wrapperCol={{
                    span: 12,
                    offset: 6,
                }}
            >
                <Button type="primary" htmlType="submit" >
                    添加
                </Button>
                <Button type="primary" onClick={()=> history.push("/")}  style={{ margin: "0 20px", }}>
                    返回首页
                </Button>
            </Form.Item>
        </Form>
    );
};
